<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 16/5/23
 * Time: 下午2:17
 * Describe:
 */

namespace console\controllers;

use console\models\Order;
use Yii;

class OrderSyncController extends \yii\console\Controller
{
    public $sys_sync_order_key = '';

    public function init()
    {
        set_time_limit(0);
        ini_set('memory_limit', '4G');
        parent::init();
        $this->sys_sync_order_key = Yii::$app->params['sys_sync_order_key'];
    }

    public function actionAddOrderInfoId()
    {
        Yii::$app->redis->lpush($this->sys_sync_order_key, 50398377);
    }

    public function actionSyncOrder()
    {
        $order = new Order();
        $i     = 0;
        while (1) {
            $i++;
            $order_info_id = Yii::$app->redis->rpop($this->sys_sync_order_key);
            echo $order_info_id;
            if (empty($order_info_id)) {
                sleep(1);
                echo 'wait', "\n";
                Yii::$app->db->createCommand("select 1;")->execute();
            } else {
                $order->order_info_id = $order_info_id;
                $order->run();
            }
            if ($i == 10) {
                #Yii::$app->getLog()->flushInterval();
            }
        }
    }
}